import { Base } from "./base";

export class Flink extends Base {
  /**
   *
   * @param name
   * @param module
   * @param pageNum
   * @param pageSize
   * @returns {Promise<void>}
   */
  // eslint-disable-next-line camelcase
  async list({ name, cate_id, pageNum = 1, pageSize = 10 }) {
    const { data = {} } = await this.$http("post", "/api/flink", {
      name,
      cate_id,
      pageNum,
      pageSize
    });
    return data;
  }

  /**
   *
   * @param id
   * @returns {Promise<boolean>}
   */
  async del(id) {
    const { errno } = await this.$http("post", "/api/flink/del", { id });
    return errno === 0;
  }

  /**
   *
   * @param name
   * @param module
   * @param title
   * @param fid
   * @param sort
   * @returns {Promise<void>}
   */
  async add({ name, cate_id, sort, url }) {
    const { data } = await this.$http("post", "/api/flink/add", {
      name,
      cate_id,
      sort,
      url
    });
    return data;
  }

  /**
   *
   * @param id
   * @param name
   * @param fname
   * @param title
   * @param sort
   * @param has_children
   * @returns {Promise<void>}
   */
  // eslint-disable-next-line camelcase
  async update({ id, name, cate_id, cate_name, sort, url }) {
    const { data } = await this.$http("post", "/api/flink/update", {
      id,
      name,
      cate_id,
      sort,
      cate_name,
      url
    });
    return data;
  }

  /**
   *
   * @param id
   * @param type
   * @returns {Promise<void>}
   */
  async detail(id) {
    const { data } = await this.$http("post", "/api/flink/detail", {
      id
    });
    return data;
  }
}
